home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH6 / EMAGA6 / common / main.cs next >
Text File  |  2005-11-23  |  7KB  |  296 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Load up defaults console values.
  8.  
  9. exec("./defaults.cs");
  10.  
  11. //-----------------------------------------------------------------------------
  12.  
  13. function initCommon()
  14. {
  15.    // All mods need the random seed set
  16.    setRandomSeed();
  17.  
  18.    // Very basic functions used by everyone
  19.    exec("./client/canvas.cs");
  20.    exec("./client/audio.cs");
  21. }
  22.  
  23. function initBaseClient()
  24. {
  25.    // Base client functionality
  26.    exec("./client/message.cs");
  27.    exec("./client/mission.cs");
  28.    exec("./client/missionDownload.cs");
  29.    exec("./client/actionMap.cs");
  30.  
  31.    // There are also a number of support scripts loaded by the canvas
  32.    // when it's first initialized.  Check out client/canvas.cs
  33. }
  34.  
  35. function initBaseServer()
  36. {
  37.    // Base server functionality
  38.    exec("./server/audio.cs");
  39.    exec("./server/server.cs");
  40.    exec("./server/message.cs");
  41.    exec("./server/commands.cs");
  42.    exec("./server/missionInfo.cs");
  43.    exec("./server/missionLoad.cs");
  44.    exec("./server/missionDownload.cs");
  45.    exec("./server/clientConnection.cs");
  46.    exec("./server/kickban.cs");
  47.    exec("./server/game.cs");
  48. }   
  49.  
  50.  
  51. //-----------------------------------------------------------------------------
  52. package Common {
  53.  
  54. function displayHelp() {
  55.    Parent::displayHelp();
  56.    error(
  57.       "Common Mod options:\n"@
  58.       "  -fullscreen            Starts game in full screen mode\n"@
  59.       "  -windowed              Starts game in windowed mode\n"@
  60.       "  -autoVideo             Auto detect video, but prefers OpenGL\n"@
  61.       "  -openGL                Force OpenGL acceleration\n"@
  62.       "  -directX               Force DirectX acceleration\n"@
  63.       "  -voodoo2               Force Voodoo2 acceleration\n"@
  64.       "  -noSound               Starts game without sound\n"@
  65.       "  -prefs <configFile>    Exec the config file\n"
  66.    );
  67. }
  68.  
  69. function parseArgs()
  70. {
  71.    Parent::parseArgs();
  72.  
  73.    // Arguments override defaults...
  74.    for (%i = 1; %i < $Game::argc ; %i++)
  75.    {
  76.       %arg = $Game::argv[%i];
  77.       %nextArg = $Game::argv[%i+1];
  78.       %hasNextArg = $Game::argc - %i > 1;
  79.    
  80.       switch$ (%arg)
  81.       {
  82.          //--------------------
  83.          case "-fullscreen":
  84.             $pref::Video::fullScreen = 1;
  85.             $argUsed[%i]++;
  86.  
  87.          //--------------------
  88.          case "-windowed":
  89.             $pref::Video::fullScreen = 0;
  90.             $argUsed[%i]++;
  91.  
  92.          //--------------------
  93.          case "-noSound":
  94.             error("no support yet");
  95.             $argUsed[%i]++;
  96.  
  97.          //--------------------
  98.          case "-openGL":
  99.             $pref::Video::displayDevice = "OpenGL";
  100.             $argUsed[%i]++;
  101.  
  102.          //--------------------
  103.          case "-directX":
  104.             $pref::Video::displayDevice = "D3D";
  105.             $argUsed[%i]++;
  106.  
  107.          //--------------------
  108.          case "-voodoo2":
  109.             $pref::Video::displayDevice = "Voodoo2";
  110.             $argUsed[%i]++;
  111.  
  112.          //--------------------
  113.          case "-autoVideo":
  114.             $pref::Video::displayDevice = "";
  115.             $argUsed[%i]++;
  116.  
  117.          //--------------------
  118.          case "-prefs":
  119.             $argUsed[%i]++;
  120.             if (%hasNextArg) {
  121.                exec(%nextArg, true, true);
  122.                $argUsed[%i+1]++;
  123.                %i++;
  124.             }
  125.             else
  126.                error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>");
  127.       }
  128.    }
  129. }
  130.  
  131. function onStart()
  132. {
  133.    Parent::onStart();
  134.    echo("\n--------- Initializing MOD: Common ---------");
  135.    initCommon();
  136. }
  137.  
  138. function onExit()
  139. {
  140.    echo("Exporting client prefs");
  141.    export("$pref::*", "./client/prefs.cs", False);
  142.  
  143.    echo("Exporting server prefs");
  144.    export("$Pref::Server::*", "./server/prefs.cs", False);
  145.    BanList::Export("./server/banlist.cs");
  146.  
  147.    OpenALShutdown();
  148.    Parent::onExit();
  149. }
  150.  
  151. }; // Common package
  152. activatePackage(Common);
  153.  
  154.  
  155.  
  156.  
  157.  
  158. function generateRandomChunkery(%parent)
  159. {
  160.    $chunkTestLevel--;
  161.    %count = getRandom(100);
  162.    
  163.    for(%i=0; %i<%count; %i++)
  164.    {
  165.       $chunkCreateCount++;
  166.       
  167.          
  168.       %obj = new TextChunk()
  169.       {
  170.          textData = "level= " @ $chunkTestLevel @ ", idx = " @ %i @ $buff;
  171.       };
  172.       
  173.       if($chunkTestLevel > 0)
  174.          generateRandomChunkery(%obj);
  175.  
  176.       %parent.add(%obj);
  177.       
  178.       // If we're hitting our limit, stop making stuff.
  179.       if($chunkCreateCount > $chunkMaxCount)
  180.          break;
  181.    }
  182.    
  183.    $chunkTestLevel++;
  184. }
  185.  
  186. function generateBigChunkTest(%buffSize, %chunkCount)
  187. {
  188.    $chunkStartTime = getRealTime();
  189.    
  190.    $chunkTestLevel = 10;
  191.    $chunkCreateCount = 0;
  192.    $chunkMaxCount = %chunkcount; // At most 16 megs of data.
  193.    
  194.    $a = getRealTime();
  195.    $buff = "";
  196.    while(strlen($buff) < %buffSize)
  197.       $buff = $buff @ "klmadskldasjkadlkjsakjlsdjksldakjlkjdlaakjlsdkljaslkjslkjdaslkjd";
  198.    $b = getRealTime();
  199.  
  200.    $root = new TextChunk() { textData = "ROOT"; };
  201.  
  202.    $c = getRealTime();
  203.    generateRandomChunkery($root);
  204.    $d = getRealTime();
  205.  
  206.    echo("Created " @ $chunkCreateCount @ " chunks in " @ $chunkTestLevel @ " levels.");
  207.    
  208.    %file = "common/bigchunktest.chunk";
  209.    echo("Saving to '" @ %file @ "'...");
  210.    $e = getRealTime();
  211.    saveChunkFile($root, %file);
  212.    $f = getRealTime();
  213.    echo("Done.");
  214.    
  215.    echo("Deleting object hierarchy...");
  216.    $root.delete();
  217.    echo("Done.");
  218.    
  219.    echo("Loading object hierarchy from '"@%file@"'...");
  220.    $g = getRealTime();
  221.    $newRoot = loadChunkFile(%file);
  222.    $h = getRealTime();
  223.    echo("Done.");
  224.    
  225.    echo("chunkCount = " @ $chunkCreateCount @ ", chunkSize=" @ %buffSize);
  226.    echo("Generated data = " @ ($chunkCreateCount * %buffSize));
  227.    echo("Elapsed time = " @ ((getRealTime() - $chunkStartTime)/1000) @ " sec.");
  228.    echo("Buffer init  = " @ (($b-$a)/1000) @ " sec.");
  229.    echo("chunk gen    = " @ (($d-$c)/1000) @ " sec.");
  230.    echo("save time    = " @ (($f-$e)/1000) @ " sec.");
  231.    echo("load time    = " @ (($h-$g)/1000) @ " sec.");
  232.    
  233.    return $newRoot;
  234. }
  235.  
  236. function testchunk()
  237. {
  238.    %foo = 
  239.    new TextChunk()
  240.    {
  241.       textData = "pony";
  242.       
  243.       new TextChunk()
  244.       {
  245.          textData = "child1";
  246.          
  247.       new TextChunk()
  248.       {
  249.          textData = "childQ";
  250.       };
  251.       };
  252.  
  253.       new TextChunk()
  254.       {
  255.          textData = "child2";
  256.       };
  257.       new TextChunk()
  258.       {
  259.          textData = "child3";
  260.  
  261.       new TextChunk()
  262.       {
  263.          textData = "childA";
  264.       };
  265.  
  266.       new TextChunk()
  267.       {
  268.          textData = "childB";
  269.       };
  270.  
  271.       new TextChunk()
  272.       {
  273.          textData = "childC";
  274.       };
  275.  
  276.       new TextChunk()
  277.       {
  278.          textData = "childD";
  279.       };
  280.  
  281.       new TextChunk()
  282.       {
  283.          textData = "childE";
  284.       };
  285.       };
  286.     };
  287.     
  288.     saveChunkFile(%foo, "starter.fps/test.chunk");
  289.     
  290.     %foo.delete();
  291.     
  292.     $foo = loadChunkFile("starter.fps/test.chunk");
  293.       
  294.       
  295. }
  296.